import { Injectable } from '@nestjs/common';
import {Like, Repository} from 'typeorm' //仓库，连接数据库
import {InjectRepository} from '@nestjs/typeorm'  //注入仓库
import {Girl} from './entities/girl.entity'
@Injectable()
export class GirlService {
  //构造函数-----装饰器（实体）------------私有的------------girl-----<泛型>
  constructor(@InjectRepository(Girl) private readonly girl:Repository<Girl>){}


  addGirl(){
    const data = new Girl()
    data.name = '三丫头';
    data.age = 25;
    data.skill = '钓鱼'
    return this.girl.save(data)
  }

  delGirl(id:number){
    return this.girl.delete(id);
  }

  updateGirl(id:number){
    const data = new Girl()
    data.age = 32
    return this.girl.update(id,data)
  }

  getGirl(){
    return this.girl.find()
  }

  getGirlByName(name:string){
    return this.girl.find({
      where:{
        name:Like(`%${name}%`)
      }
    })
  }
  getGirlByskill(skill:string){
    return this.girl.find({
      where:{
        skill:Like(`%${skill}%`)
      }
    })
  }
}
